﻿using RpcCacheClient.Interface;
using RpcExtend.DAL;
using RpcExtend.Model;

namespace RpcExtend.Collect.Collect
{
    internal class IdentityProwerCollect : IIdentityProwerCollect
    {
        private readonly IIdentityProwerDAL _BasicDAL;
        private readonly ICacheController _Cache;
        public IdentityProwerCollect(IIdentityProwerDAL basicDAL, ICacheController cache)
        {
            this._Cache = cache;
            this._BasicDAL = basicDAL;
        }


        public void Refresh(Guid appId, string systemType)
        {
            string key = string.Join("_", "IdPrower", appId.ToString("N"), systemType);
            this._Cache.Remove(key);
        }
        public IdentityPrower[] GetPrower(Guid appId, string systemType)
        {
            string key = string.Join("_", "IdPrower", appId.ToString("N"), systemType);
            if (this._Cache.TryGet(key, out IdentityPrower[] prowers))
            {
                return prowers;
            }
            prowers = this._BasicDAL.GetPrower(appId, systemType);
            this._Cache.Set(key, prowers, new TimeSpan(31, 0, 0, 0));
            return prowers;
        }
    }
}
